#!/usr/bin/python3.7
# -*- coding: utf-8 -*-
# @Time    : 2021/3/17 18:18
# @Author  : cs
# @File    : 7.45.py
# @Software: PyCharm
class SparseArray:
    def __init__(self):
        self._array = []

    def __len__(self):
        return len(self._array)

    def __getitem__(self, item):
        is_exists = False
        index = None
        for i in range(len(self._array)):
            if self._array[i][0] == item:
                is_exists = True
                index = i
                break
        if is_exists:
            return self._array[index][1]
        else:
            raise IndexError

    def __setitem__(self, key, value):
        is_exists = False
        index = None
        for i in range(len(self._array)):
            if self._array[i][0] == key:
                is_exists = True
                index = i
                break
        if is_exists:
            self._array[index][1] = value
        else:
            raise IndexError

    def append(self, item):
        self._array.append(item)

if __name__ == "__main__":
    array = SparseArray()
    array.append([1,5])
    print(array[1])
